// pages/submitConsultation/index.js

import {
  ApiOrderDrug,
  ApiPayTest
} from "../../api/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: false,
  },

  /*   opt={"fileList":["files/user/20241129/20241129151019_9XFdq0dIcbWY787704c88d6ffa79d6c68ea1e609c34f.jpg"],"text_Area":"222"}&defalueData={"id":2,"uid":1,"relation":"家人","name":"张三","card_type":"居民身份证","card_no":"410522199802079351","nation":"汉族","card_file":"","area":"湖北省-荆门市-沙洋县","area_detail":"碧桂园七号","phone":"13164640638","gender":"男","birth":"1998-02-07","medical_card":"","use":1,"created_at":"2024-11-28 10:29:01","updated_at":"2024-11-28 15:24:35"}&doctorInfo={"id":1,"name":"内科医生","department":"消化内科","icon":"files/admin/20241129/20241129131303_20241129.jpg","level":"主治医师","introduce":"专业擅长","order_count":3,"score":0,"price":"0.00"} */
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      opt: JSON.parse(options.order)
    })
    let a = this.computedCountDown(this.data.opt.created_at)
    this.setData({
      countDown: a
    })
  },

  /*   opt={"type":"new","order":{"order_no":"JY20241203000000030","order_type":"图文问诊","uid":1,"order_time":"2024-12-03 11:40-11:49","target":"健康咨询","doctor_id":"1","doctor_name":"内科医生","department_id":"1","department_name":"消化内科","amount":"18.00","status":1,"patient_id":"2","patient_name":"张三","patient_area":"湖北省-荆门市-沙洋县碧桂园七号","patient_phone":"13164640638","card_no":"410522199802079351","medical_card":"","patient_pic":"files/user/20241203/20241203131626_QKUyjWuL4kL30b87c30622f9659709a7dd7fd34497be.png","patient_status":"2321321231","updated_at":"2024-12-03 13:16:33","created_at":"2024-12-03 13:16:33","id":36}} */
  computedCountDown(data) {
    const givenTime = new Date(data); // UTC时间表示
    const updatedTime = new Date(givenTime.getTime() + 15 * 60 * 1000);
    // 当前时间
    const currentTime = new Date();
    // 计算时间差（毫秒）
    const timeDifference = updatedTime - currentTime;
    return timeDifference
  },



  submitConsultation() {
    let that = this
    this.setData({
      isLoading: true
    })
    ApiOrderDrug(that.data.opt.id).then(res => {
      if (res.code == '200') {
        //删除storage
        /*   wx.removeStorage({
            key: 'priceDetail',
          }) */

        wx.requestPayment({
          ...res.data,
          success(res) {
            that.setData({
              isLoading: false
            })
            wx.reLaunch({
              url: `/pages/drugRecordDetail/index?id=${that.data.opt.id}`
            })
          },
          fail(res) {
            that.setData({
              isLoading: false
            })
          }


        })


      }
    })
  },


  //快速支付
  quickConsultation() {
    let that = this
    ApiPayTest({
      order_type: '2',
      order_id: this.data.opt.id
    }).then(res => {
      wx.redirectTo({
        url: `/pages/drugRecordDetail/index?id=${that.data.opt.id}`
      })
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})